package com.hmdp.controller;


import com.hmdp.dto.Result;
import com.hmdp.service.IFollowService;
import com.hmdp.utils.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 虎哥
 * @since 2021-12-22
 */
@RestController
@RequestMapping("/follow")
@Slf4j
public class FollowController {

    @Autowired
    private IFollowService followService;

    @GetMapping("/or/not/{id}")
    public Result isFollow(@PathVariable Long id){
        log.info("用户：{} 查询是否关注用户{}", UserHolder.getUser().getId(),id);

        return followService.isFollow(id);

    }

    @PutMapping("/{id}/{isFollow}")
    public Result follow(@PathVariable Long id,@PathVariable Boolean isFollow){

        log.info("用户：{} 选择关注或取关：{}"+ isFollow, UserHolder.getUser().getId(),id);
        return followService.follow(id,isFollow);
    }

    @GetMapping("common/{id}")
    public Result commonFollow(@PathVariable Long id){
        log.info("用户：{}查询和{}的共同关注", UserHolder.getUser().getId(),id);

        return followService.commonFollow(id);
    }





}
